import { SetMetadata } from "@nestjs/common";
import { Decorator } from "../enum/decorator.enum";
import { Role } from "../enum/role.enum";
import { Entity, LogParams } from "./type";

/** 公开方法, 即不需要身份验证 */
export const Public = () => SetMetadata(Decorator.IS_PUBLIC_KEY, true);

/** 将当前操作写入日志库 */
export const CreateLog = (logParams: LogParams, entity: Entity | null, saveRequestData: boolean = true) =>
    SetMetadata(Decorator.CREATE_LOG_KEY, { ...logParams, entity, saveRequestData });

/** 角色权限 */
export const Roles = (...roles: Role[]) => SetMetadata(Decorator.ROLE_KEY, roles);
